package org.jackysoft.service.impl;

import java.util.List;
import java.util.Map;

import org.jackysoft.data.SortInfo;
import org.jackysoft.entity.nosql.SecurityRoleNotify;
import org.jackysoft.service.AbstractNoSqlServiceImpl;
import org.jackysoft.service.SecurityRoleNotifyService;
import org.springframework.stereotype.Service;

import com.mongodb.BasicDBObject;
import com.mongodb.DBCursor;
import com.mongodb.DBObject;

@Service
public class SecurityRoleNotifyServiceImpl 
extends	AbstractNoSqlServiceImpl<SecurityRoleNotify> 
implements SecurityRoleNotifyService {

	/**
	 * 
	 */
	private static final long serialVersionUID = -6480632720683962366L;

	public SecurityRoleNotifyServiceImpl() {
		super(SecurityRoleNotify.class);
	}

	@Override
	public void doneEvent(String id) {
		
		SecurityRoleNotify sr = new SecurityRoleNotify();
		sr.setId(id);
		sr.setDone(true);	
		super.update(sr);
		
	}

	@Override
	protected List<SecurityRoleNotify> searchData(int start, int size,
			boolean listAll, SortInfo sortInfo, Map<String, Object> smap) {
		String done  = ((String[]) smap.get("done"))[0];	
		DBObject query = new BasicDBObject("done",done);
		DBCursor dbcur = collection.find(query)
				.sort(new BasicDBObject("done","desc"))
				.sort(new BasicDBObject("modifyDate","desc"))
				.skip(start).limit(size);
		
		return this.fromMongodbList(dbcur.toArray());
	}

	@Override
	protected int searchDataSize(SortInfo sortInfo, Map<String, Object> smap) {
		String done  = ((String[]) smap.get("done"))[0];	
		DBObject query = new BasicDBObject("done",done);
		Long len = collection.count(query);
		return len.intValue();
	}
	
	
	
	
	
    
	
}
